package com.huawei.eservice.demo;


import org.openqa.selenium.By;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.MalformedURLException;
import java.net.URL;

import io.appium.java_client.android.AndroidDriver;

public class CalculatorTest {

    public static void main(String[] args) throws MalformedURLException, InterruptedException {

        DesiredCapabilities capabilities = new DesiredCapabilities();

        capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
        capabilities.setCapability("platformName", "Android");                               // 指定测试平台
        capabilities.setCapability("deviceName", "emulator-5556");                       // 指定测试机的ID,通过adb命令`adb
        capabilities.setCapability("platformVersion", "6.0");                                // 设置测试机的版本
        capabilities.setCapability("appPackage", "com.android.calculator2");                 // 将上面获取到的包名和Activity名设置为值
        capabilities.setCapability("appActivity", ".Calculator");
        capabilities.setCapability("appWaitActivity", "com.android.calculator2.Calculator"); // A new session could not be created的解决方法
        capabilities.setCapability("sessionOverride", true);

        AndroidDriver driver = new AndroidDriver(new URL("http://192.168.1.109:4723/wd/hub"), capabilities);

        driver.findElement(By.name("1")).click();
        driver.findElement(By.name("5")).click();
        driver.findElement(By.name("9")).click();
        driver.findElement(By.name("delete")).click();
        driver.findElement(By.name("+")).click();
        driver.findElement(By.name("6")).click();
        driver.findElement(By.name("=")).click();
        Thread.sleep(2000);

        String result = driver.findElementById("com.android.calculator2:id/formula").getText();
        System.out.println(result);

        driver.quit();
    }

}
